import Vue from 'vue';
import Vuex from 'vuex';
// import createLogger from 'vuex/dist/logger';
import createPersistedState from 'vuex-persistedstate';

// 自动适别modules下的模块
const req = require.context('./modules', true, /\.js$/);
var modules = {};
var reg = /.\/(.*).js/;
req.keys().map((item) => {
  var name = reg.exec(item)[1];
  modules[name] = require('./modules/' + name + '.js').default;
});
Vue.use(Vuex);
var createStore = [createPersistedState({
  paths: ['app'],
  storage: window.sessionStorage
})];
// if (process.env.NODE_ENV !== 'production') {
//   createStore.push(createLogger());
// }
export default new Vuex.Store({
  modules: modules,
  plugins: createStore
});
